Cache Key Management
(MI.Cache, MI.ComputedCacheKey)
Overview
The CDN assigns a unique identifier (a cache key) to each object in the CDN cache. The cache key is generated from the URI of the content request. Use the Cache Key Management feature to customize cache key generation.
Two SVTA objects support customizing cache key generation to support your caching strategies.
-
MI.Cache: Use this object to set basic cache key management rules: exclude path pattern, include/exclude all or specified query parameters. When you use this object to configure the cache key rules, the hostname is added implicitly to the cache key to allow for the unique identification of objects across different hosts.
-
MI.ComputedCacheKey: Use this object to configure a more complex rule with a MEL expression. For example, to set conditions on the query parameters or share cached objects across multiple different hosts.
Basic Cache Key Management (MI.Cache)
Overview
You can use the MI.Cache object to set basic rules for cache key generation (exclude path pattern, include/exclude all or specified query parameters). When you use the MI.Cache object to configure the cache key rules, the hostname is added implicitly to the cache key. This ensures the unique identification of objects across different hosts sharing the same path and query parameters.
Examples
Include the full URI and exclude all query parameters.
In this example, the cache key is constructed using the full URI but no query parameters.
{
"generic-metadata-type": "MI.Cache",
"generic-metadata-value": {
"exclude-path-pattern": "",
"include-query-strings": []
}
}
"exclude-path-pattern": ""
- No path segments are specified, so the cache key uses the entire path.
"include-query-strings": []
- No query strings are specified, so the cache key excludes all query parameters.
Include the full URI and all query parameters.
In this example, include-query-strings
field is omitted, so all query strings are included in the cache key.
{
"generic-metadata-type": "MI.Cache",
"generic-metadata-value": {
"exclude-path-pattern": ""
}
}
Exclude a path segment and include specified query parameters.
In this example, the cache key excludes any URI path segment that begins with userid (e.g., /userid123/
) and includes only the version
query parameter.
{
"generic-metadata-type": "MI.Cache",
"generic-metadata-value": {
"exclude-path-pattern": "/userid*/",
"include-query-strings": [
"version"
]
}
}
Supported Properties
Field | Description |
---|---|
exclude-path-pattern (optional) | A glob-style pattern that excludes matching parts of the request path from the cache key. See below. |
include-query-strings (optional) | Controls whether and which query parameters from the client request URL are included in the cache key. See below. |
exclude-path-pattern
A glob-style pattern that excludes matching parts of the request path from the cache key. When there is a match, the matching path segment is excluded from the cache key. If there is no match, or if this property omitted or empty (""
), the full URI path is used to construct the cache key.
You can use wildcards to define a pattern:
* | Represents any sequence of alphanumeric or '/' characters. |
? | Represents exactly one character. |
For example, /userid*/
would exclude the userid segment of the request URL from the cache key.
include-query-strings
Controls whether and which query string parameters from the client request URL are included in the cache key.
-
Use an array of one or more values (strings)
["param1", "param2"]
to specify the parameters to include.For example,
"version","timestamp"
adds the version and timestamp to the cache key. -
Omit this property to include all query parameters in the cache key.
-
Use an empty array
[]
to exclude all query parameters from the cache key.
Note that the hostname is implicitly added to the cache key.
Advanced Cache Key Management (MI.ComputedCacheKey)
Overview
Use the MI.ComputedCacheKey object for advanced cache key requirements that go beyond simple path exclusion or query parameter filtering. This object supports using a MEL expression to define the cache key, enabling conditional logic based on request headers, cookies, or specific query parameter values. Use advanced cache key management when you need to design a cache key that can be shared across different hostnames. (MI.Cache implicitly includes the hostname.)
The JSON format:
{
"generic-metadata-type": "MI.ComputedCacheKey",
"generic-metadata-value": {
"expression": "<MEL expression>"
}
}
Example
In this example, the cache key is constructed from the hostname req.h.host
and the rightmost path segment path_element(req.uri.path , -1)
(typically the filename), concatenated with &
to create the cache key.
{
"generic-metadata-type": "MI.ComputedCacheKey",
"generic-metadata-value": {
"expression": "req.h.host . '&' . path_element(req.uri.path , -1) "
}
}
In this case, these URIs would generate the same cache key because they share the same hostname and rightmost path values:
-
example.com/path/to/file-12345.mp4
-
example.com/another/path/to/file-12345.mp4
Supported Properties
Field | Description |
---|---|
expression | A MEL expression that defines how the cache key should be constructed. Use this to combine or transform request attributes (such as headers, query parameters, or path segments) using conditional logic or string manipulation. |